package cn.it.ygh.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONArray;
import cn.it.ygh.annotation.SystemLog;
import cn.it.ygh.pojo.Agent;
import cn.it.ygh.pojo.User;
import cn.it.ygh.service.AgentCheckService;

@Controller("agentCheckController")
@RequestMapping("/agentCheck")
public class AgentCheckController {
	
	@Resource
	private AgentCheckService agentCheckService;
	
	@RequestMapping(value="/getPageData.do",method=RequestMethod.GET)
	@SystemLog(description="查看中介的申请信息")
	@ResponseBody
	public Map<Object, Object> getPageData(@RequestParam(value = "curr") int curr,@RequestParam(value = "pageSize") int pageSize,@RequestParam(value = "key") String key)
	{
		List<Agent> agentList = agentCheckService.getPageData((curr-1)*pageSize, pageSize,key);
		System.out.println(curr);
		System.out.println(pageSize);
		System.out.println(key);
		int totalRecord = agentCheckService.getTotalRecord(key);
		Map<Object, Object> info = new HashMap<Object, Object>();
		info.put("data", agentList);
		info.put("total", totalRecord);
		JSONArray array = new JSONArray();
		array.addAll(agentList);
		System.out.println(array.toString());
		return info;
	}
	
	@RequestMapping(value="/passAgent.do")
	@SystemLog(description="确认中介申请")
	public ModelAndView passAgent(@RequestParam(value = "agentId") int agentId)
	{
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("../admin/jsp/agent-check");
		agentCheckService.passAgent(agentId);
		return modelAndView;
	}
	
	@RequestMapping(value="/rejectAgent.do")
	@SystemLog(description="拒绝中介申请")
	public ModelAndView rejectAgent(@RequestParam(value = "agentId") int agentId)
	{
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.setViewName("../admin/jsp/agent-check");
		agentCheckService.rejectAgent(agentId);
		return modelAndView;
	}
	
	@RequestMapping(value="/updateCheckMsg.do")
	@ResponseBody
	public Map<Object, Object> updateCheckMsg(){
		Map<Object, Object> info = new HashMap<Object, Object>();
		info.put("msgcount", agentCheckService.getCheckMsg());
		return info;
	} 
}
